package com.bitcarton.disso.core.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wwd
 */
public class SsoClientUtil {
    /**
     * @param request
     * @return
     */
    public static String getRedirectUrl(HttpServletRequest request, String ssoClientUrl,String ssoName) {
        return ssoClientUrl + request.getServletPath();
    }

    /**
     * @param request
     * @param response
     * @throws IOException
     */
    public static void redirectToSsoUrl(HttpServletRequest request, HttpServletResponse response, String ssoClientUrl, String ssoServerUrl,String ssoName) throws IOException {
        String redirectUrl = getRedirectUrl(request, ssoClientUrl,ssoName);
        StringBuilder url = new StringBuilder(50)
                .append(ssoServerUrl)
                .append("/checkLogin?redirectUrl=")
                .append(redirectUrl);
        response.sendRedirect(url.toString());
    }


    /**
     * @return
     */
    public static String getClientLogOutUrl(String ssoClientUrl, String ssoLogoutPath) {
        return ssoClientUrl + ssoLogoutPath;
    }


    public static void redirectToSsoLoginUrl(HttpServletRequest req, HttpServletResponse response, String ssoClientUrl, String ssoServerUrl) throws IOException {
        StringBuilder url = new StringBuilder(50)
                .append(ssoServerUrl)
                .append("/checkLogin");
        response.sendRedirect(url.toString());
    }



}
